Skip to content

Refactor and update QR Op #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2025

Conversation

jessegrabowski
Copy link
Member

@jessegrabowski jessegrabowski commented Jul 2, 2025

Description

This PR updates the QRFull Op, adding static shape checking, infer_shape, and destroy_map. It also optimizes the perform method for the C backend, and tries to improve the gradient graph by checking static shapes (to avoid an ifelse).

I renamed it to QR, because I don't know what was Full about the old one. I also moved it from the numpy implementation to scipy, which gives us all the usual benefits (inplace, etc). I also went ahead and unpacked the scipy wrapper and used the LAPACK functions directly. This will give us better error handling (that is to say, none -- it should eventually return a matrix of NaN on failure) and some performance boost by caching workspace requirements.

Still a WIP, because it breaks everything by moving QR from nlinalg to slinalg. I thought about using this as an opportunity to finally eliminate this distinction and go to a more logical organization (linalg/decomposition/qr.py), but then decided against it for now. Needs discussion.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1518.org.readthedocs.build/en/1518/

@jessegrabowski jessegrabowski added enhancement New feature or request maintenance linalg Linear algebra labels Jul 2, 2025
@jessegrabowski jessegrabowski force-pushed the qr-shape-inference branch 3 times, most recently from 5bc044c to be949cd Compare July 3, 2025 00:57
@jessegrabowski jessegrabowski force-pushed the qr-shape-inference branch 4 times, most recently from 71639ef to a6d6c11 Compare July 9, 2025 07:37
@jessegrabowski jessegrabowski marked this pull request as ready for review July 9, 2025 07:39
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

Attention: Patch coverage is 49.75530% with 308 lines in your changes missing coverage. Please review.

Project coverage is 81.45%. Comparing base (b9fc4f8) to head (112f6fd).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...sor/link/numba/dispatch/linalg/decomposition/qr.py 19.41% 274 Missing ⚠️
pytensor/link/numba/dispatch/slinalg.py 63.41% 10 Missing and 5 partials ⚠️
pytensor/tensor/slinalg.py 93.58% 5 Missing and 7 partials ⚠️
pytensor/link/pytorch/dispatch/slinalg.py 77.77% 4 Missing ⚠️
pytensor/link/numba/dispatch/linalg/_LAPACK.py 85.00% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (49.75%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1518      +/-   ##
==========================================
- Coverage   81.85%   81.45%   -0.41%     
==========================================
  Files         230      232       +2     
  Lines       52522    53027     +505     
  Branches     9345     9422      +77     
==========================================
+ Hits        42992    43192     +200     
- Misses       7095     7390     +295     
- Partials     2435     2445      +10     
Files with missing lines Coverage Δ
pytensor/link/jax/dispatch/nlinalg.py 93.47% <ø> (-0.76%) ⬇️
pytensor/link/jax/dispatch/slinalg.py 94.84% <100.00%> (+0.33%) ⬆️
pytensor/link/numba/dispatch/nlinalg.py 100.00% <ø> (ø)
pytensor/link/pytorch/dispatch/__init__.py 100.00% <100.00%> (ø)
pytensor/link/pytorch/dispatch/nlinalg.py 78.00% <ø> (+2.59%) ⬆️
pytensor/tensor/nlinalg.py 94.98% <ø> (-0.65%) ⬇️
pytensor/link/numba/dispatch/linalg/_LAPACK.py 79.78% <85.00%> (+0.49%) ⬆️
pytensor/link/pytorch/dispatch/slinalg.py 77.77% <77.77%> (ø)
pytensor/tensor/slinalg.py 93.41% <93.58%> (+0.01%) ⬆️
pytensor/link/numba/dispatch/slinalg.py 68.39% <63.41%> (-1.38%) ⬇️
... and 1 more

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

in_dtype = config.floatX if integer_input else dtype

@numba_njit(cache=False)
def qr(a):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about a not being F-contiguous like other lapack/blas stuff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it's done in the lower level functions

@jessegrabowski jessegrabowski merged commit 617964f into pymc-devs:main Jul 15, 2025
72 of 73 checks passed
@jessegrabowski jessegrabowski deleted the qr-shape-inference branch July 15, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request linalg Linear algebra maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add infer_shape method to QRFull
2 participants